<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="./../layui/css/layui.css" media="all">
    <script src="./../layui/layui.js"></script>
    <script src="./../js/jquery-1.8.3.min.js"></script>
    <script src="./../js/env.js"></script>
    <title>管理充电桩</title>
    <style>
        .layui-btn-group {
            margin: 10px 10px;
        }
    </style>
</head>

<body>

<fieldset class="layui-elem-field layui-field-title">
    <legend>管理充电桩</legend>
</fieldset>
<div class="demoTable">
    <button type="button" class="layui-btn" style="margin-left: 10px;margin-bottom: 10px" onclick="javascript :history.back(-1)">返回</button>
    <button type="button" class="layui-btn" style="margin-left: 2px;margin-bottom: 10px" onclick="add()">新增</button>
</div>
<form method="get" action="" class="layui-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-inline">
                <select id="acDc" lay-filter="quiz3">
                    <option value="">请选择</option>
                    <option value="1">直流</option>
                    <option value="2">交流</option>

                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">创建时间</label>
            <div class="layui-input-inline">
                <input type="text" id="date1" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">————</label>
            <div class="layui-input-inline">
                <input type="text" id="date2" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>


        <button class="layui-btn" onclick="sech()" data-method="offset" type="button">搜索</button>
    </div>

</form>
<table id="demo" lay-filter="test"></table>
</body>

</html>

<script type="text/html" id="barDemo">
    <button type="button" onclick="edit('{{d.id}}')" class="layui-btn layui-btn-sm layui-btn-normal" lay-event="edit"
            style="background: dodgerblue">编辑
    </button>
    <button type="button" onclick="deleteArea('{{d.id}}')" class="layui-btn layui-btn-sm layui-btn-normal"
            lay-event="edit" style="background: red">删除
    </button>
</script>
<script>
    if (layui.sessionData('user').userInfo === undefined) {
        window.location.href = "../html/login.html"
    }
    layui.use(['form', 'layedit', 'laydate', 'upload', 'table'], function () {

        var table = layui.table;
        var laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#date1', type: "datetime"
        });
        laydate.render({
            elem: '#date2', type: "datetime"
        });

        var tableParam = {};
        tableParam.chargingStationsId = getParam("id")
        tableParam.acDc = $("#acDc").val()
        tableParam.startDate = $("#date1").val()
        tableParam.endDate = $("#date2").val()

        //第一个实例
        table.render({
            elem: '#demo',
            where: tableParam,
            id: "testReload"
            , page: true //开启分页
            , headers: {sessionId: getToken()}
            , url: abc() + '/admin/chargeStation/selectAllChargingPileInfos' //数据接口
            , cols: [[ //表头
                {field: 'id', title: 'id', sort: true, fixed: 'left', align: 'center'}
                , {field: 'serialNumber', title: '编号', align: 'center'}
                , {field: 'parkingLotNo', title: '车位号', align: 'center'}
                , {field: 'rateOfWork', title: '功率', align: 'center'}
                , {
                    field: 'acDc', title: '类型', templet: function (val) {
                        if (val.acDc == 1) {
                            return "直流";
                        } else {
                            return "交流";
                        }
                    }, align: 'center'
                }
                , {field: 'openStartTime', title: '开放开始时间', align: 'center'}
                , {field: 'openEndTime', title: '开放结束时间', align: 'center'}
                , {field: 'price', title: '价格单位元度', align: 'center'}
                , {field: 'serviceCharge', title: '服务费 价格元/度'}
                , {field: 'timestamp', title: '修改时间', align: 'center'}
                , {field: 'right', title: '操作', width: 150, toolbar: '#barDemo', align: 'center'}
            ]]
            , request: {
                pageName: 'page' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , done: function (res, curr, count) {
                if (res.code === 100) {
                    layer.msg("登录失效，请重新登录")
                    window.location.href = "../html/login.html"
                    return;
                }
            }
            , parseData: function (res) { //res 即为原始返回的数据
                if (res.code !== 0) {
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg //解析提示文本
                    };
                } else {
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.list //解析数据列表
                    };
                }

            }
        });

    });

    function sech() {
        var tableParam = {};
        tableParam.chargingStationsId = getParam("id")
        tableParam.acDc = $("#acDc").val()
        tableParam.startDate = $("#date1").val()
        tableParam.endDate = $("#date2").val()

        //表刷新方法
        var table = layui.table;
        table.reload('testReload', {
            url: abc() + '/admin/chargeStation/selectAllChargingPileInfos'
            , where: tableParam
        });

    }

    function add() {
        window.location.href = "./add/charge_info_add.html?chargingStationsId=" + getParam("id");
    }

    function edit(id) {
        window.location.href = "./add/charge_info_edit.html?id=" + id + "&chargingStationsId=" + getParam("id");
    }

    function deleteArea(id) {
        layer.confirm('确定删除?', function (index) {
            var param = {};
            param.id = id;
            var respones = MyAjax("GET", "/admin/chargeStation/delChargingPileInfo", param, getToken());
            if (respones.code === 0) {
                layer.msg("删除成功");
                //表刷新方法
                var table = layui.table;
                table.reload('testReload', {
                    url: abc() + '/admin/chargeStation/selectAllChargingPileInfos'
                });
            }
        });
    }
</script>